package com.shop.cereshop.business.dl.logic.controller;

import com.shop.cereshop.business.dl.logic.domian.CareShopColumn;
import com.shop.cereshop.business.dl.logic.service.CareShopColumnService;
import com.shop.cereshop.business.dl.logic.utils.ResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 况鑫威
 * @Date: 2021/6/16
 * @Time: 11:52
 * @ClassName: DlCareShopColumnController
 * @Description: com.shop.cereshop.business.dl.logic.controller
 */
@RestController
@Slf4j(topic = "DlCareShopColumnController")
@CrossOrigin
@RequestMapping("/business")
public class DlCareShopColumnController {
    @Autowired
    private CareShopColumnService careShopColumnService;

    /**
     * 功能描述: 获取全部栏目
     * @Param: []
     * @Return: com.shop.cereshop.business.dl.logic.utils.ResultInfo
     * @Author: 况鑫威
     * @Date: 2021/6/16
     * @Time: 11:55
     */
    @PostMapping("/getAll")
    public ResultInfo getAll(){
        return new ResultInfo(careShopColumnService.getAll());
    }


    /**
     * 功能描述: 添加栏目
     * @Param: []
     * @Return: com.shop.cereshop.business.dl.logic.utils.ResultInfo
     * @Author: 况鑫威
     * @Date: 2021/6/16
     * @Time: 13:34
     */
    @PostMapping("/add")
    public ResultInfo add(String title){
        if(title == null || "".equals(title)){
            return ResultInfo.error("请输入栏目名");
        }
        if(careShopColumnService.add(title) > 0){
            return ResultInfo.ok();
        }else{
            return ResultInfo.error("操作失败");
        }
    }


    /**
     * 功能描述: 修改栏目
     * @Param: [careShopColumn]
     * @Return: com.shop.cereshop.business.dl.logic.utils.ResultInfo
     * @Author: 况鑫威
     * @Date: 2021/6/18
     * @Time: 13:48
     */
    @PostMapping("/update")
    public ResultInfo update(CareShopColumn careShopColumn){
        if(careShopColumn.getTitle() == null || "".equals(careShopColumn.getTitle())){
            return ResultInfo.error("请输入栏目名");
        }
        return new ResultInfo(careShopColumnService.updateByPrimaryKeySelective(careShopColumn));
    }
}
